import java.util.Scanner;

public class Num {
    public static void main(String []args){
        int a[] = new int [100];
        @SuppressWarnings("resource")
        Scanner sc=new Scanner(System.in);
        System.out.println("请输入数组长度");
        int len = sc.nextInt();
        System.out.println("请输入"+len+"个数字");
        for(int i=0;i<len;i++) {
            a[i] = sc.nextInt();
        }
        int max = maxSubSum(a,len);
        System.out.println("所有子数组的和的最大值为:"+max);
    }

    static int maxSubSum(int[] a,int length) {
        int i=0;
        int len = length;
        for(i=1;i<len;i++){
            if(a[i]+a[i-1]>a[i]) {
                a[i]=a[i]+a[i-1];
            }
        }
        int ans=-100000;
        for(i=0;i<len;i++) {
            if(ans<a[i]) {
                ans = a[i];
            }
        }
        return ans;
    }
}
